<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script>
    // 方法一
    var arr1 = [2, 0, 6, 1, 77, 0, 52, 34, 24, 56, 20];
    var arr2 = [];
    var j = 0;
    for (var i = 0; i < arr1.length; i++) {
      if (arr1[i] >= 20) {
        // 新数组应该从0 开始，依次递增
        arr2[j] = arr1[i];
        j++;
      }
    }
    console.log(arr2);

    // 方法二
    var arr1 = [2, 0, 6, 1, 77, 0, 52, 34, 24, 56, 20];
    var arr2 = [];
    // 刚开始 arr2.length 就是0
    for (var i = 0; i < arr1.length; i++) {
      if (arr1[i] >= 20) {
        // 新数组应该从0 开始，依次递增
        arr2[arr2.length] = arr1[i];
      }
    }
    console.log(arr2);
  </script>
</head>

<body>

</body>

</html>